package coreutil

import (
	"core/corestruct"
	"errors"
	"time"
)

type dateUtil struct {
}

func (p *dateUtil) StrToDate(s string) (*time.Time, error) {
	if len(s) != 10 {
		return nil, errors.New("日期格式错误")
	}
	s = s[0:10]
	var dt, err = time.Parse(corestruct.DateFmt, s)
	if err != nil {
		return nil, err
	}
	return &dt, nil
}

func (p *dateUtil) DateToStr(t *time.Time) string {
	return t.Format(corestruct.DateFmt)
}
func (p dateUtil) NowStr() string {
	return time.Now().Format(corestruct.DateTimeFmt)
}
func (p dateUtil) TodayStr() string {
	return time.Now().Format(corestruct.DateFmt)
}

var (
	DateUtil = &dateUtil{}
)
